using UnityEngine;
using System.Collections;

/// \class  gkSpawningCylindricalPositionModifier
/// \brief  Select a cylindrical position
[AddComponentMenu("GK/Engine/Game/Spawn/gkSpawningCylindricalPositionModifier")]
public class gkSpawningCylindricalPositionModifier : gkSpawningModifier 
{
	/// The velocity direction
	public Vector3 CylindricalPositionMin = new Vector3(0,0,0);

	/// The velocity direction
	public Vector3 CylindricalPositionMax = new Vector3(0,0,0);
	
	/// Modify the X velocity ?
	public bool ModifyX = true;
	
	/// Modify the X velocity ?
	public bool ModifyY = true;
	
	/// Modify the X velocity ?
	public bool ModifyZ = true;
	
	/// \brief  Event called at the and of the actor spawn
	public override void ModifySpawnedActor(GameObject a_rSpawnedActor, int a_iNumActorsInCurrentBatch, int a_iNbActorsInCurrentBatch)
	{
		RandomCylindricalPositionChange(a_rSpawnedActor);
	}
	
	/// \brief  Random velocity change
	void RandomCylindricalPositionChange(GameObject a_rSpawnedActor)
	{
		Vector3 f3RandomCylindricalPosition;
		gkCylindricalPosition rCylindricalPosition;
		
		// Grab the cylindrical position
		rCylindricalPosition = a_rSpawnedActor.GetComponent<gkCylindricalPosition>();
		
		// Get the current positin
		f3RandomCylindricalPosition = rCylindricalPosition.position;
		
		// Override X velocity if needed
		if(ModifyX)
		{
			f3RandomCylindricalPosition.x = Random.Range(CylindricalPositionMin.x, CylindricalPositionMax.x);				
		}
		
		// Override Y velocity if needed
		if(ModifyY)
		{
			f3RandomCylindricalPosition.y = Random.Range(CylindricalPositionMin.y, CylindricalPositionMax.y);				
		}
		
		// Override Z velocity if needed
		if(ModifyZ)
		{
			f3RandomCylindricalPosition.z = Random.Range(CylindricalPositionMin.z, CylindricalPositionMax.z);				
		}
		
		// Set the cylindrical position
		rCylindricalPosition.position = f3RandomCylindricalPosition;
	}
}
